package DAO;

import java.io.*;
import java.math.*;
import java.util.*;
import javax.crypto.*;
import java.security.*;
import javax.crypto.spec.*;
import java.security.interfaces.*;

public class Cryptage {

  public final static int KEY_SIZE = 128;  // [32..448]

  private Key secretKey;
  private static String password="toto";
  
  
  public Cryptage() {
      
          try {
      KeyGenerator keyGen = KeyGenerator.getInstance("Blowfish");
      keyGen.init(KEY_SIZE);
      secretKey = new SecretKeySpec(password.getBytes(), "Blowfish");
    }
    catch (Exception e) {System.out.println(e);} 
 
  }


  public byte[] crypt(byte[] plaintext) {
    try {
      Cipher cipher = Cipher.getInstance("Blowfish");
      cipher.init(Cipher.ENCRYPT_MODE, secretKey);
      return cipher.doFinal(plaintext);    
    }
    catch (Exception e) {System.out.println(e);} 
    return null;
  }

  
  public byte[] crypt(String plaintext) {
    return crypt(plaintext.getBytes());
  }
  


  
}